package top.milkbox.core;

public class R<T> {

    private String code;
    private T data;
    private String message;

    public R(String code, T data, String message) {
        this.code = code;
        this.data = data;
        this.message = message;
    }

    public static <T> R<T> data(T data) {
        return new R<>("200", data, "操作成功");
    }

    public static <T> R<T> error() {
        return error("服务器异常");
    }

    public static <T> R<T> error(String errorMessage) {
        return new R<>("500", null, errorMessage);
    }

    public static <T> R<T> ok() {
        return ok("操作成功");
    }

    public static <T> R<T> ok(String okMessage) {
        return new R<>("200", null, okMessage);
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
